home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / e_to_l / edsspell / edsspell.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  29.2 KB  |  880 lines

  1. (* EDSSPELL.PAS - Copyright (c) 1995-1996, Eminent Domain Software *)
  2.  
  3. unit EDSSpell;
  4.   {-Component Wrapper for Spell Dialog}
  5.  
  6. {$I SpellDef.PAS}
  7.   {-defines for EDSSpell component}
  8.  
  9. interface
  10. uses
  11.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  12.   Forms, Dialogs, StdCtrls, Buttons, Menus, ExtCtrls,
  13.   SpellGbl, AbsBuff, AbsSpell, LexDCT, WPSpell,
  14. {$IFNDEF Shareware}
  15.   MSSpell, W96Spell,
  16. {$ENDIF}
  17. {$IFDEF SupportOrpheus}
  18.   OvcEdit, OvcEF, OvcBuff,
  19. {$ENDIF}
  20. {$IFDEF SupportTXText}
  21.   TXBuff, Tx4vb,
  22. {$ENDIF}
  23. {$IFDEF SupportWPTools}
  24.   WPRich, WPBuff,
  25. {$ENDIF}
  26.   SpellInt;
  27.  
  28. type
  29.   {Dialog Component Wrapper}
  30.   TSpellDlg = class (TComponent)
  31.   private
  32.     FPath:           TFileName;
  33.     FDictionary:     TFileName;
  34.     FDicType:        TLanguages;
  35.     FLanguage:       TLanguages;
  36.     FDialogType:     TDialogTypes;
  37.     FSpellWin:       TAbsSpellDialog;
  38.     FSuggestions:    Byte;
  39.     FIcons:          TAccentSet;
  40.     FAutoSuggest:    Boolean;
  41.     FAutoShift:      Boolean;
  42.     FHelpContext:    THelpContext;
  43.     FUserDCT:        TFileName;
  44.     {Lists of words}
  45.     FSkipList:       TStringList;  {List of words to skip}
  46.     FReplaceList:    TStringList;  {List of words to auto-replace}
  47.     FReplacer:       TStringList;  {List of words to replace above list with}
  48.     FReplaceNum:     integer;      {index of word in replace list}
  49.     procedure   SetDicType (NewType: TLanguages);
  50.       {-sets the new dictionary type}
  51.     procedure   SetLanguage (NewLanguage: TLanguages);
  52.       {-sets the language for the label}
  53.     procedure   SetDialogType (NewType: TDialogTypes);
  54.       {-sets the dailog type}
  55.     procedure   SetSuggestions (Num: Byte);
  56.       {-sets the number of suggestions}
  57.     procedure   SetIconSet (IconSet: TAccentSet);
  58.       {-sets the icons to be visible}
  59.     procedure   SetHelpContext (HelpID: THelpContext);
  60.       {-sets the help context for the spell component}
  61.     function    CheckBuffer (ABuffer: TAbsBuffer): Integer;
  62.       {-checks the buffer}
  63.   public
  64.     constructor Create (AOwner: TComponent); override;
  65.       {-initializes object}
  66.     destructor  Destroy;  override;
  67.       {-destroys object}
  68.     function    Open: Boolean;
  69.       {-opens the dictionary}
  70.     procedure   Close;
  71.       {-closes the dictionary and removes the dialog}
  72.     procedure   ClearLists;
  73.       {-clears the SkipList, ReplaceList, and Replacer List}
  74.     procedure   MoveDialog (YPos: Integer);
  75.       {-moves the dialog so that it does not highlighted word}
  76.     procedure   EnableSkipButtons;
  77.       {-enables the skip buttons on the dialog}
  78.     procedure   DisableSkipButtons;
  79.       {-disables the skip buttons on the dialog}
  80.     procedure   Show;
  81.       {-displays the dialog}
  82.     function    CheckWord (var AWord: String): Integer;
  83.       {-checks the word (see AbsSpell for CheckWord results)}
  84.     function    CheckCustomEdit (ACustomEdit: TCustomEdit): Integer;
  85.       {-checks a custom edit control}
  86.     function    CheckMemo (AMemo: TMemo): Integer;
  87.       {-checks the memo}
  88. (*  function    CheckDBMemo (ADBMemo: TDBMemo): Integer; *)
  89. (*     -use CheckCustomEdit instead:                     *)
  90. (*          CheckCustomEdit (DBMemo1);                   *)
  91.     function    CheckEdit (AnEdit: TEdit): Integer;
  92.       {-checks a TEdit control}
  93. {$IFDEF SupportOrpheus}
  94.     function    CheckOvcEditor (AnOvcEdit: TOvcCustomEditor): Integer;
  95.       {-checks an Orpheus editor component}
  96.     function    CheckOvcField (AnOvcField: TOvcBaseEntryField): Integer;
  97.       {-checks an Orpheus field component}
  98. {$ENDIF}
  99. {$IFDEF SupportTXText}
  100.     function    CheckTXControl (ATXControl: TTextControl): Integer;
  101.       {-checks a TXTextControl}
  102. {$ENDIF}
  103. {$IFDEF SupportWPTools}
  104.     function    CheckWPText (AWPRichText: TWPRichText): Integer;
  105.       {-checks a WPTools RTF Component}
  106. {$ENDIF}
  107.     function    CheckAllFields (AForm: TForm; DisplayMsg: Boolean): Integer;
  108.       {-checks all of the edit fields on the form}
  109.  
  110.     {---- Word Counters ----}
  111.     procedure   CustomEdit_WordCount (ACustomEdit: TCustomEdit; var NumWords, UniqueWords: Longint);
  112.       {-returns the number of words in a TCustomEdit}
  113.     procedure   Memo_WordCount (AMemo: TMemo; var NumWords, UniqueWords: Longint);
  114.       {-returns the number of words in a TMemo}
  115.     procedure   Edit_WordCount (AnEdit: TEdit; var NumWords, UniqueWords: Longint);
  116.       {-returns the number of words in a TEdit}
  117. {$IFDEF SupportOrpheus}
  118.     procedure   OvcEdit_WordCount (AnOvcEdit: TOvcCustomEditor;
  119.                                    var NumWords, UniqueWords: Longint);
  120.       {-returns the number of words in a TOvcCustomEditor}
  121.     procedure   OvcField_WordCount (AnOvcField: TOvcBaseEntryField;
  122.                                     var NumWords, UniqueWords: Longint);
  123.       {-returns the number of words in a TOvcBaseEntryField}
  124. {$ENDIF}
  125. {$IFDEF SupportTXText}
  126.     procedure   TXText_WordCount (ATXControl: TTextControl;
  127.                                   var NumWords, UniqueWords: Longint);
  128.       {-returns the number of words in a TX Text-Control}
  129. {$ENDIF}
  130.  
  131.  
  132.     {---- Internal Routines (No Dialog) ----}
  133.     function    OpenDictionary: Boolean;
  134.       {-opens the dictionary}
  135.     procedure   CloseDictionary;
  136.       {-closes the dictionary}
  137.     function    AddWord (AWord: string): Boolean;
  138.       {-adds a word to the dictionary, returns TRUE if successful}
  139.     function    InDictionary (AWord: String): Boolean;
  140.       {-checks to see if the word is in the dictionary (no dialog)}
  141.     function    SuggestWords (AWord: String; NumToList: Byte): TStringList;
  142.       {-suggests words}
  143.     {Lists of words}
  144.     property SkipList:      TStringList read FSkipList write FSkipList;
  145.     property ReplaceList:   TStringList read FReplaceList write FReplaceList;
  146.     property Replacer:      TStringList read FReplacer write FReplacer;
  147.   published
  148.     property AccentIcons:    TAccentSet read FIcons write SetIconSet;
  149.     property AutoShift:      Boolean read FAutoShift write FAutoShift;
  150.     property AutoSuggest:    Boolean read FAutoSuggest write FAutoSuggest;
  151.     property DialogStyle:    TDialogTypes read FDialogType write SetDialogType;
  152.     property DictionaryName: TFileName read FDictionary write FDictionary;
  153.     property DictionaryPath: TFileName read FPath write FPath;
  154.     property DictionaryType: TLanguages read FDicType write SetDicType;
  155.     property LabelLanguage:  TLanguages read FLanguage write SetLanguage;
  156.     property Suggestions:    Byte read FSuggestions write SetSuggestions;
  157.     property HelpContext:    THelpContext read FHelpContext write SetHelpContext;
  158.     property UserDictionary: TFileName read FUserDCT write FUserDCT;
  159.   end;  { TSpellDlg }
  160.  
  161. procedure Register;
  162.  
  163. implementation
  164.  
  165. {---- TSpellDlg.Wrapper ----}
  166. constructor TSpellDlg.Create (AOwner: TComponent);
  167. begin
  168.   inherited Create (AOwner);
  169.   FSpellWin      := nil;
  170.   FDialogType    := dtWordPerfect;
  171.   FIcons         := [];
  172.   FAutoShift     := TRUE;
  173.   FAutoSuggest   := FALSE;
  174.   FDictionary    := '';
  175.   FPath          := 'APPLICATIONPATH';
  176.   FUserDCT       := 'USERDCT.TXT';
  177.   FDicType       := lgEnglish;
  178.   FLanguage      := lgEnglish;
  179.   SetDialogType (FDialogType);
  180.   Suggestions    := 10;
  181. end; { TSpellDlg.Create }
  182.  
  183. destructor TSpellDlg.Destroy;
  184. begin
  185.   CloseDictionary;
  186.   {FSpellWin is automatically destroyed by parent}
  187.   {FSpellWin.Destroy implied}
  188.   inherited Destroy;
  189. end;  { TSpellDlg.Destroy }
  190.  
  191. procedure TSpellDlg.SetDicType (NewType: TLanguages);
  192.   {-sets the new dictionary type}
  193. begin
  194.   FDicType := NewType;
  195.   case FDicType of
  196.     lgSpanish: Include (FIcons, acSpanish);
  197.   end;  { case }
  198. end;  { TSpellDlg.SetDicType }
  199.  
  200. procedure TSpellDlg.SetLanguage (NewLanguage: TLanguages);
  201.   {-sets the language for the label}
  202. var
  203.   LangMesg: string;
  204. begin
  205.   FLanguage := NewLanguage;
  206.   if FSpellWin <> nil then
  207.     FSpellWin.Language := FLanguage;
  208. end;  { TSpellDlg.SetLanguage }
  209.  
  210. procedure TSpellDlg.SetDialogType (NewType: TDialogTypes);
  211.   {-sets the dailog type}
  212. var
  213.   dtMesg: string;
  214. begin
  215.   if csDesigning in ComponentState then
  216.   begin
  217. {$IFDEF Shareware}
  218.     if NewType in [dtMSWord, dtWordPro96] then
  219.     begin
  220.       MessageDlg ('MSWord and WordPro96 dialogs are not'+#13+
  221.                   'supported in shareware version.', mtInformation,
  222.                   [mbOk], 0);
  223.     end {:} else
  224.       FDialogType := NewType;
  225. {$ELSE}
  226.     FDialogType := NewType;
  227. {$ENDIF}
  228.   end {:} else
  229.   begin
  230.     FDialogType := NewType;
  231.     if FSpellWin<>nil then
  232.     begin
  233.       FSpellWin.Free;
  234.       FSpellWin := nil;
  235.     end;  { if... }
  236.     case FDialogType of
  237.       dtWordPerfect: FSpellWin := TWPSpellDlg.Create (Owner);
  238. {$IFNDEF Shareware}
  239.       dtMSWord: FSpellWin := TMSSpellDlg.Create (Owner);
  240.       dtWordPro96: FSpellWin := TW96SpellDlg.Create (Owner);
  241. {$ENDIF}
  242.     end;  { case }
  243.     FSpellWin.SetAccentSet (FIcons);
  244.   end;  { if... }
  245. end;  { TSpellDlg.SetDialogType }
  246.  
  247. procedure TSpellDlg.SetSuggestions (Num: Byte);
  248. begin
  249.   if Num>255 then
  250.   begin
  251.     MessageDlg ('Maximum limit suggestions is 255.',
  252.                 mtInformation, [mbOk], 0);
  253.     FSuggestions := 255;
  254.   end {:} else
  255.   if Num<1 then
  256.   begin
  257.     MessageDlg ('Invlid number of suggestions.',
  258.                 mtInformation, [mbOk], 0);
  259.     FSuggestions := 1;
  260.   end {:} else
  261.     FSuggestions := Num;
  262.   if FSpellWin <> nil then
  263.     FSpellWin.Suggestions := FSuggestions;
  264. end;  { TSpellDlg.SetSuggestions }
  265.  
  266. procedure TSpellDlg.SetIconSet (IconSet: TAccentSet);
  267. begin
  268.   FIcons := IconSet;
  269.   if FSpellWin <> nil then
  270.     FSpellWin.SetAccentSet (FIcons);
  271. end;  { TSpellDlg.SetIconSet }
  272.  
  273. procedure TSpellDlg.SetHelpContext (HelpID: THelpContext);
  274.   {-sets the help context for the spell component}
  275. begin
  276.   FHelpContext := HelpID;
  277.   if FSpellWin<>nil then
  278.     FSpellWin.HelpContext := FHelpContext;
  279. end;  { TSpellDlg.SetHelpContext }
  280.  
  281. function TSpellDlg.Open: Boolean;
  282.   {-opens the dictionary and prepares dialog}
  283. begin
  284.   Result      := TRUE;    {assume success}
  285.   SkipList    := TStringList.Create;
  286.   ReplaceList := TStringList.Create;
  287.   Replacer    := TStringList.Create;
  288.   if not OpenDictionary then
  289.   begin
  290.     MessageDlg ('Error opening dictionary '+ FPath + FDictionary,
  291.                 mtError, [mbOk], 0);
  292.     Close;
  293.     Result := FALSE;
  294.   end;  { if... }
  295. end;  { TSpellDlg.Open }
  296.  
  297. procedure TSpellDlg.Close;
  298.   {-closes the dictionary and removes the dialog}
  299. begin
  300.   SkipList.Free;
  301.   ReplaceList.Free;
  302.   Replacer.Free;
  303.   if FSpellWin <> nil then
  304.     FSpellWin.Hide;
  305.   CloseDictionary;
  306. end;  { TSpellDlg.Close }
  307.  
  308. procedure TSpellDlg.ClearLists;
  309.   {-clears the SkipList, ReplaceList, and Replacer List}
  310. begin
  311.   SkipList.Clear;
  312.   ReplaceList.Clear;
  313.   Replacer.Clear;
  314. end;  { TSpellDlg.ClearLists }
  315.  
  316. procedure TSpellDlg.MoveDialog (YPos: integer);
  317.   {-moves the dialog so that it does not highlighted word}
  318. var
  319.   CenterY: integer;
  320. begin
  321.   if YPos <> 0 then
  322.   begin
  323.     CenterY := Screen.Height div 2;
  324.     if YPos > CenterY
  325.       then FSpellWin.Top := Margin
  326.       else FSpellWin.Top := Screen.Height - FSpellWin.Height - Margin;
  327.   end;  { if... }
  328. end;  { TSpellDlg.MoveDialog }
  329.  
  330. procedure TSpellDlg.EnableSkipButtons;
  331.   {-enables the skip buttons on the dialog}
  332. begin
  333.   if FSpellWin <> nil then
  334.     FSpellWin.EnableSkipButtons;
  335. end;  { TSpellDlg.EnableSkipButtons }
  336.  
  337. procedure TSpellDlg.DisableSkipButtons;
  338.   {-disables the skip buttons on the dialog}
  339. begin
  340.   if FSpellWin <> nil then
  341.     FSpellWin.DisableSkipButtons;
  342. end;  { TSpellDlg.DisableSkipButtons }
  343.  
  344. procedure TSpellDlg.Show;
  345.   {-displays the dialog}
  346. begin
  347.   {Set up window}
  348.   FSpellWin.Left := (Screen.Width div 2) - (FSpellWin.Width div 2);
  349.   if AutoShift then MoveDialog (Margin);
  350.   FSpellWin.Show;
  351. end;  { TSpellDlg.Show }
  352.  
  353. function TSpellDlg.CheckBuffer (ABuffer: TAbsBuffer): Integer;
  354.   {-checks the buffer}
  355. var
  356.   WordSt:       string;       {current word}
  357.   MessageSt:    string;       {message string}
  358.   CloseWin:     Boolean;      {TRUE if close window at end}
  359.   NoErrors:     Boolean;      {TRUE if all words are spelled correctly}
  360.   WinResult:    Byte;         {Result from ShowModal call}
  361.   WordAdded:    Boolean;      {TRUE if a word was added}
  362.   WordChanged:  Boolean;      {TRUE if a word was changed on the memo}
  363.   sModified:    Boolean;      {saves current Modified status of buffer}
  364. begin
  365.   Result      := mrNone;
  366.   sModified   := ABuffer.Modified;
  367.   WordAdded   := FALSE;
  368.   WordChanged := FALSE;
  369.   CloseWin    := FALSE;
  370.   if not Open then Exit;
  371.   if not FSpellWin.Visible then
  372.   begin
  373.     Show;
  374.     CloseWin := TRUE;
  375.   end {:} else
  376.     if AutoShift then MoveDialog (ABuffer.YPos);
  377.   with ABuffer do
  378.   begin
  379.     {calculate the upper most bounds for the memo}
  380.     {assume entire document for now}
  381.     FSpellWin.SpellDlgResult := mrNone;
  382.     FSpellWin.ClearSuggestList;
  383.     NoErrors := TRUE;
  384.     repeat
  385.       if Modified then
  386.       begin
  387.         WordChanged := TRUE;
  388.         UpdateBuffer;
  389.         MoveBackOneWord;
  390.         Modified := FALSE;
  391.       end;  { if... }
  392.       WordSt := GetNextWord;
  393.       if (Length (WordSt) > 1) and (not AllNumbers) and
  394.          (not InDictionary (WordSt)) then
  395.       begin
  396.         FReplaceNum := ReplaceList.IndexOf (LowerCase (WordSt));
  397.         if FReplaceNum <> (-1) then
  398.         begin
  399.           {word in replace list}
  400.           SetSelectedText;
  401.           if AutoShift then MoveDialog (YPos);
  402.           ReplaceWord (Replacer[FReplaceNum]);
  403.         end {:} else
  404.         if SkipList.IndexOf (LowerCase (WordSt)) = (-1) then
  405.         begin
  406.           {word not in skip list}
  407.           NoErrors := FALSE;
  408.           SetSelectedText;
  409.           if AutoShift then MoveDialog (YPos);
  410.           FSpellWin.SetNotFoundPrompt (NotFoundPhrase[FLanguage]);
  411.  
  412.           FSpellWin.SetNotFoundCaption (WordSt);
  413.           FSpellWin.SetEditWord (WordSt);
  414.           Application.ProcessMessages;
  415.           if FAutoSuggest then
  416.             FSpellWin.MakeSuggestions;
  417.           FSpellWin.SpellDlgResult := 0;
  418.           FSpellWin.SetEditAsActive;
  419.           repeat
  420.             if Application.Active then FSpellWin.Show;
  421.             Application.ProcessMessages;
  422.           until (FSpellWin.SpellDlgResult <> 0) or (not FSpellWin.Visible);
  423.           if not FSpellWin.Visible
  424.             then WinResult := mrCancel
  425.             else WinResult := FSpellWin.SpellDlgResult;
  426.           case WinResult of
  427.             mrReplace:
  428.               begin
  429.                 WordSt := LowerCase (WordSt);
  430.                 if WordSt <> LowerCase (FSpellWin.GetEditWord) then
  431.                 begin
  432.                   ReplaceWord (FSpellWin.GetEditWord);
  433.                   FSpellWin.SetEditWord ('');
  434.                 end;  { if... }
  435.               end;  { Replace }
  436.             mrAdd:
  437.               begin
  438.                 {Add to dictionary}
  439.                 WordSt := FSpellWin.GetEditWord;
  440.                 if not InDictionary (WordSt) then
  441.                 begin
  442.                   case FLanguage of
  443.                     lgEnglish: MessageSt := 'Add "' + WordSt + '" to dictionary?';
  444.                     lgSpanish: MessageSt := '┐Quieres a±adir "' + WordSt + '" al diccionario?';
  445.                     lgItalian: MessageSt := '┐Quieres a±adir "' + WordSt + '" al diccionario?';
  446.                     lgDutch:   MessageSt := 'Add "' + WordSt + '" to dictionary?';
  447.                   end;  { case }
  448.                   if MessageDlg (MessageSt, mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  449.                     DCT.AddWord (WordSt);
  450.                   WordAdded := TRUE;
  451.                 end {:} else
  452.                 begin
  453.                   case FLanguage of
  454.                     lgEnglish: MessageSt := '"' + WordSt + '" already in dictionary.';
  455.                     lgSpanish: MessageSt := '"' + WordSt + '" ya esta en el diccionario.';
  456.                     lgItalian: MessageSt := '┐Quieres a±adir "' + WordSt + '" al diccionario?';
  457.                     lgDutch:   MessageSt := '"' + WordSt + '" already in dictionary.';
  458.                   end;  { case }
  459.                   MessageDlg (MessageSt, mtInformation, [mbOk], 0);
  460.                 end;  { else }
  461.                 FSpellWin.SetEditAsActive;
  462.               end;  { Add }
  463.             mrSkipOnce: {do nothing};
  464.             mrSkipAll:
  465.               begin
  466.                 {add word to skiplist}
  467.                 WordSt := LowerCase (WordSt);
  468.                 SkipList.Add (WordSt);
  469.               end;  { SkipAll }
  470.             mrReplaceAll:
  471.               begin
  472.                 {add word to replacelist}
  473.                 WordSt := LowerCase (WordSt);
  474.                 if WordSt <> LowerCase (FSpellWin.GetEditWord) then
  475.                 begin
  476.                   ReplaceList.Add (WordSt);  {the bad word}
  477.                   Replacer.Add (FSpellWin.GetEditWord);
  478.                   ReplaceWord (FSpellWin.GetEditWord);
  479.                   FSpellWin.SetEditWord ('');
  480.                 end;  { if... }
  481.               end;  { ReplaceAll }
  482.             mrCancel:
  483.               begin
  484.                 WinResult := mrCancel;
  485.                 break;
  486.               end;  { Cancel }
  487.           end;  { case }
  488.         end;  { if... }
  489.         FSpellWin.ClearSuggestList;
  490.       end {:} else
  491.       begin
  492.         FSpellWin.SetNotFoundPrompt (FoundPhrase[FLanguage]);
  493.         FSpellWin.SetNotFoundCaption (WordSt);
  494.         Application.ProcessMessages;
  495.         if FSpellWin.SpellDlgResult = mrCancel then
  496.         begin
  497.           {I said stop!}
  498.           WinResult := mrCancel;
  499.           Break;
  500.         end;  { if... }
  501.       end;  { else }
  502.     until WordSt='';
  503.     if CloseWin then FSpellWin.Hide;
  504.     Modified := WordChanged or sModified;
  505.     if DCT.Open then DCT.CloseDictionary;
  506.   end;  { with }
  507.   if WinResult=mrCancel then
  508.   begin
  509.     MessageSt := AbortedMesg[FLanguage];
  510.     Result    := mrCancel;
  511.   end {:} else
  512.   if NoErrors then
  513.   begin
  514.     MessageSt := NoErrorsMesg[FLanguage];
  515.     Result    := mrNone;
  516.   end {:} else
  517.   begin
  518.     MessageSt := CompleteMesg[FLanguage];
  519.     Result    := mrOk;
  520.   end;  { else }
  521.   if CloseWin then
  522.     MessageDlg (MessageSt, mtInformation, [mbOk], 0);
  523. end;  { TSpellDlg.CheckBuffer }
  524.  
  525. function TSpellDlg.CheckWord (var AWord: String): Integer;
  526.   {-checks the word (see AbsSpell for CheckWord results)}
  527. var
  528.   LabelSt: string;
  529. begin
  530.   if not FSpellWin.Visible then
  531.      Open ; {-open current dictionary}
  532.   {Set up window}
  533.   FSpellWin.Left := (Screen.Width div 2) - (FSpellWin.Width div 2);
  534.   {FSpellWin.FormStyle := fsStayOnTop;}
  535.   {if AutoShift then MoveDialog (AMemo);}
  536.   FSpellWin.SetNotFoundCaption (AWord);
  537.   FSpellWin.SetEditWord (AWord);
  538.   if InDictionary (AWord) then
  539.   begin
  540.     FSpellWin.SetNotFoundPrompt (FoundPhrase[FLanguage]);
  541.   end {:} else
  542.   begin
  543.     FSpellWin.SetNotFoundPrompt (NotFoundPhrase[FLanguage]);
  544.     if FAutoSuggest then
  545.       FSpellWin.MakeSuggestions;
  546.     FSpellWin.SpellDlgResult := 0;
  547.     repeat
  548.       Show;
  549.       Application.ProcessMessages;
  550.     until (FSpellWin.SpellDlgResult <> 0) or (not FSpellWin.Visible);
  551.     if not FSpellWin.Visible
  552.       then Result := mrReplace
  553.       else Result := FSpellWin.SpellDlgResult;
  554.     if Result = mrReplace
  555.       then AWord := FSpellWin.GetEditWord;
  556.   end;  { else }
  557. end;  { TSpellDlg.CheckWord }
  558.  
  559. function TSpellDlg.CheckCustomEdit (ACustomEdit: TCustomEdit): Integer;
  560. var
  561.   CEBuf:       TCEBuffer;    {buffer manager for memo}
  562.   sSelStart:   Longint;      {saves the current attributes of Memo}
  563.   sSelLength:  Longint;      { '' }
  564.   sHideSel:    Boolean;      { '' }
  565. begin
  566.   sSelStart           := ACustomEdit.SelStart;
  567.   sSelLength          := ACustomEdit.SelLength;
  568.   if ACustomEdit is TMemo then
  569.     with ACustomEdit as TMemo do
  570.     begin
  571.       sHideSel := HideSelection;
  572.       HideSelection := FALSE;
  573.     end
  574.   else
  575.   if ACustomEdit is TEdit then
  576.     with ACustomEdit as TEdit do
  577.     begin
  578.       sHideSel := HideSelection;
  579.       HideSelection := FALSE;
  580.     end;  { with }
  581.   CEBuf  := TCEBuffer.Create (ACustomEdit);
  582.   Result := CheckBuffer (CEBuf);
  583.   CEBuf.Free;
  584.   ACustomEdit.SelStart      := sSelStart;
  585.   ACustomEdit.SelLength     := sSelLength;
  586.   if ACustomEdit is TMemo then
  587.     with ACustomEdit as TMemo do
  588.       HideSelection := sHideSel
  589.   else
  590.   if ACustomEdit is TEdit then
  591.     with ACustomEdit as TEdit do
  592.       HideSelection := sHideSel;
  593. end; { TSpellDlg.CheckCustomEdit }
  594.  
  595. function TSpellDlg.CheckMemo (AMemo: TMemo): Integer;
  596. begin
  597.   Result := CheckCustomEdit (AMemo);
  598. end; { TSpellDlg.CheckMemo }
  599.  
  600. function TSpellDlg.CheckEdit (AnEdit: TEdit): Integer;
  601. begin
  602.   Result := CheckCustomEdit (AnEdit);
  603. end;  { TSpellDlg.CheckEdit }
  604.  
  605. {$IFDEF SupportOrpheus}
  606. function TSpellDlg.CheckOvcEditor (AnOvcEdit: TOvcCustomEditor): Integer;
  607.   {-checks an Orpheus editor component}
  608. var
  609.   OvcBuf:         TOrpheusEditor;
  610.   sLine1, sLine2: Longint;
  611.   sCol1, sCol2:   Integer;
  612.   cLine:          Longint;
  613.   cCol:           Integer;
  614.   sCursorPos:     Integer;
  615.   sHideSel:       Boolean;
  616. begin
  617.   with AnOvcEdit do
  618.   begin
  619.     sHideSel := HideSelection;   {save hide selection setting}
  620.     HideSelection := FALSE;
  621.     cLine := AnOvcEdit.GetCaretPosition (cCol);  {save caret pos}
  622.     GetSelection (sLine1, sCol1, sLine2, sCol2); {save select info}
  623.     OvcBuf := TOrpheusEditor.Create (AnOvcEdit);
  624.     Result := CheckBuffer (OvcBuf);
  625.     OvcBuf.Free;
  626.     {set all settings back}
  627.     SetSelection (sLine1, sCol1, sLine2, sCol2, FALSE);
  628.     SetCaretPosition (cLine, cCol);
  629.     HideSelection := sHideSel;
  630.   end; { with }
  631. end;  { TSpellDlg.CheckOvcEditor }
  632.  
  633. function TSpellDlg.CheckOvcField (AnOvcField: TOvcBaseEntryField): Integer;
  634.   {-checks an Orpheus field component}
  635. var
  636.   OvcBuf:      TOrpheusField;
  637.   sSelStart:   Longint;      {saves the current attributes of Field}
  638.   sSelLength:  Longint;      { '' }
  639.   sHideSel:    Boolean;      { '' }
  640.   sCursorPos:  Longint;      { '' }
  641. begin
  642.   with AnOvcField do  {save field attributes}
  643.   begin
  644.     sSelStart  := SelectionStart;
  645.     sSelLength := SelectionLength;
  646.     sCursorPos := CurrentPos;
  647.   end;  { with }
  648.   OvcBuf := TOrpheusField.Create (AnOvcField);
  649.   Result := CheckBuffer (OvcBuf);
  650.   OvcBuf.Free;
  651.   with AnOvcField do  {restore field attributes}
  652.   begin
  653.     SelectionStart   := sSelStart;
  654.     SelectionLength  := sSelLength;
  655.     CurrentPos       := sCursorPos;
  656.   end;  { with }
  657. end;  { TSpellDlg.CheckOvcField }
  658. {$ENDIF}
  659.  
  660. {$IFDEF SupportTXText}
  661. function TSpellDlg.CheckTXControl (ATXControl: TTextControl): Integer;
  662.   {-checks a TXTextControl}
  663. var
  664.   TXBuf:       TTXTextBuf;   {buffer manager for text control}
  665.   sSelStart:   Longint;      {saves the current attributes of Memo}
  666.   sSelLength:  Longint;      { '' }
  667.   sHideSel:    Boolean;      { '' }
  668. begin
  669.   sSelStart   := ATXControl.SelStart;
  670.   sSelLength  := ATXControl.SelLength;
  671.   with ATXControl as TTextControl do
  672.   begin
  673.     sHideSel := HideSelection;
  674.     HideSelection := FALSE;
  675.   end;  { with }
  676.   TXBuf  := TTXTextBuf.Create (ATXControl);
  677.   Result := CheckBuffer (TXBuf);
  678.   TXBuf.Free;
  679.   ATXControl.SelStart      := sSelStart;
  680.   ATXControl.SelLength     := sSelLength;
  681.   with ATXControl as TTextControl do
  682.     HideSelection := sHideSel;
  683. end;  { TSpellDlg.CheckTXControl }
  684. {$ENDIF}
  685.  
  686. {$IFDEF SupportWPTools}
  687. function TSpellDlg.CheckWPText (AWPRichText: TWPRichText): Integer;
  688.   {-checks a WPTools RTF Component}
  689. var
  690.   WPBuf:       TWPBuf;      {buffer manager for WpTools}
  691.   sSelStart:   Longint;      {saves the current attributes of Memo}
  692.   sSelLength:  Longint;      { '' }
  693. begin
  694.   sSelStart   := AWPRichText.SelStart;
  695.   sSelLength  := AWPRichText.SelLength;
  696.   WPBuf  := TWPBuf.Create (AWPRichText);
  697.   Result := CheckBuffer (WPBuf);
  698.   WPBuf.Free;
  699.   AWPRichText.SelStart  := sSelStart;
  700.   AWPRichText.SelLength := sSelLength;
  701. end;  { TSpellDlg.CheckWPText }
  702. {$ENDIF}
  703.  
  704. function TSpellDlg.CheckAllFields (AForm: TForm; DisplayMsg: Boolean): Integer;
  705.   {-checks all of the edit fields on the form}
  706. var
  707.   SpellResult:   integer;
  708.   NoErrors:      Boolean;
  709.   MessageSt:     string;
  710.   i:             integer;
  711. begin
  712.   {find the form's spell dialog}
  713.   SpellResult := mrNone;
  714.   NoErrors := TRUE;
  715.   Open;
  716.   Show;
  717.   for i := 0 to AForm.ComponentCount - 1 do
  718.   begin
  719.     if (AForm.Components[i] is TCustomEdit) then
  720.       SpellResult :=  CheckCustomEdit (TCustomEdit (AForm.Components[i]))
  721. {$IFDEF SupportOrpheus}
  722.     else
  723.     if (AForm.Components[i] is TOvcCustomEditor) then
  724.       SpellResult :=  CheckOvcEditor (TOvcCustomEditor (AForm.Components[i]))
  725.     else
  726.     if (AForm.Components[i] is TOvcBaseEntryField) then
  727.       SpellResult :=  CheckOvcField (TOvcBaseEntryField (AForm.Components[i]))
  728. {$ENDIF}
  729. {$IFDEF SupportTXText}
  730.     else
  731.     if (AForm.Components[i] is TCustomEdit) then
  732.       SpellResult :=  CheckTXControl (TTextControl (AForm.Components[i]))
  733. {$ENDIF}
  734. {$IFDEF SupportWpTools}
  735.     else
  736.     if (AForm.Components[i] is TCustomEdit) then
  737.       SpellResult :=  CheckWPText (TWPRichText (AForm.Components[i]))
  738. {$ENDIF};
  739.     if SpellResult = mrCancel then
  740.       Break
  741.     else
  742.     if SpellResult = mrOk then
  743.       NoErrors := FALSE;
  744.   end; { next i }
  745.   Close;
  746.   if (SpellResult = mrNone) and (not NoErrors) then
  747.     SpellResult := mrOk;
  748.   if DisplayMsg then
  749.   begin
  750.     case SpellResult of
  751.       mrNone:   MessageSt := NoErrorsMesg[FLanguage];
  752.       mrCancel: MessageSt := AbortedMesg[FLanguage];
  753.       mrOk:     MessageSt := CompleteMesg[FLanguage];
  754.     end;  { case }
  755.     MessageDlg (MessageSt, mtInformation, [mbOk], 0);
  756.   end;  { if... }
  757.   Result := SpellResult;
  758. end;  { TForm1.CheckAllFields }
  759.  
  760. {---- Word Counters ----}
  761. procedure TSpellDlg.CustomEdit_WordCount (ACustomEdit: TCustomEdit; var NumWords, UniqueWords: Longint);
  762.   {-returns the number of words in a TCustomEdit}
  763. var
  764.   CEBuf: TCEBuffer;
  765. begin
  766.   CEBuf := TCEBuffer.Create (ACustomEdit);
  767.   CEBuf.WordCount (NumWords, UniqueWords);
  768.   CEBuf.Free;
  769. end;  { TSpellDlg.CustomEdit_WordCount }
  770.  
  771. procedure TSpellDlg.Memo_WordCount (AMemo: TMemo; var NumWords, UniqueWords: Longint);
  772.   {-returns the number of words in a TMemo}
  773. begin
  774.   CustomEdit_WordCount (AMemo, NumWords, UniqueWords);
  775. end;  { TSpellDlg.Memo_WordCount }
  776.  
  777. procedure TSpellDlg.Edit_WordCount (AnEdit: TEdit; var NumWords, UniqueWords: Longint);
  778.   {-returns the number of words in a TEdit}
  779. begin
  780.   CustomEdit_WordCount (AnEdit, NumWords, UniqueWords);
  781. end;  { TSpellDlg.Edit_WordCount }
  782.  
  783. {$IFDEF SupportOrpheus}
  784. procedure TSpellDlg.OvcEdit_WordCount (AnOvcEdit: TOvcCustomEditor;
  785.                                        var NumWords, UniqueWords: Longint);
  786.   {-returns the number of words in a TOvcCustomEditor}
  787. var
  788.   OvcEditBuf: TOrpheusEditor;
  789. begin
  790.   OvcEditBuf := TOrpheusEditor.Create (AnOvcEdit);
  791.   OvcEditBuf.WordCount (NumWords, UniqueWords);
  792.   OvcEditBuf.Free;
  793. end;  { TSpellDlg.OvcEdit_WordCount }
  794.  
  795. procedure TSpellDlg.OvcField_WordCount (AnOvcField: TOvcBaseEntryField;
  796.                                         var NumWords, UniqueWords: Longint);
  797.   {-returns the number of words in a TOvcBaseEntryField}
  798. var
  799.   OvcFieldBuf: TOrpheusField;
  800. begin
  801.   OvcFieldBuf := TOrpheusField.Create (AnOvcField);
  802.   OvcFieldBuf.WordCount (NumWords, UniqueWords);
  803.   OvcFieldBuf.Free;
  804. end;  { TSpellDlg.OvcField_WordCount }
  805. {$ENDIF}
  806.  
  807. {$IFDEF SupportTXText}
  808. procedure TSpellDlg.TXText_WordCount (ATXControl: TTextControl;
  809.                                       var NumWords, UniqueWords: Longint);
  810.   {-returns the number of words in a TX Text-Control}
  811. var
  812.   TXBuf: TTXTextBuf;
  813. begin
  814.   TXBuf := TTXTextBuf.Create (ATXControl);
  815.   TXBuf.WordCount (NumWords, UniqueWords);
  816.   TXBuf.Free;
  817. end;  { TSpellDlg.TXText_WordCount }
  818. {$ENDIF}
  819. {---- Internal Routines (No Dialog) ----}
  820.  
  821. function  TSpellDlg.OpenDictionary: Boolean;
  822.   {-opens the dictionary; returns TRUE if successful}
  823. begin
  824.   Result := TRUE;  {assume dictionary opens fine}
  825.   if DictionaryName='' then
  826.     DictionaryName := UpperCase (Dictionaries[DictionaryType] + DCTExt);
  827.   DictionaryPath := UpperCase (DictionaryPath);
  828.   if DictionaryPath = 'APPLICATIONPATH' then
  829.     DictionaryPath := ExtractFilePath (Application.ExeName)
  830.   else
  831.   if Length (DictionaryPath)>0 then
  832.     if DictionaryPath[Length(DictionaryPath)]<>'\' then
  833.       DictionaryPath := DictionaryPath + '\';
  834.   if DCT = nil then
  835.     DCT := TDictionary.Create;
  836.   if not DCT.OpenDictionary (DictionaryPath + DictionaryName,
  837.                              UserDictionary) then
  838.   begin
  839.     Result := FALSE;
  840.     DCT.Free;
  841.     DCT := nil;
  842.   end;  { if... }
  843. end;  { TSpellDlg.OpenDictionary }
  844.  
  845. procedure TSpellDlg.CloseDictionary;
  846.   {-closes the dictionary}
  847. begin
  848.   if DCT <> nil then
  849.   begin
  850.     DCT.CloseDictionary;
  851.     DCT.Free;
  852.     DCT := nil;
  853.   end;  { if... }
  854. end;  { TSpellDlg.CloseDictionary }
  855.  
  856. function TSpellDlg.AddWord (AWord: string): Boolean;
  857.   {-adds a word to the dictionary, returns TRUE if successful}
  858. begin
  859.   Result := DCT.AddWord (AWord);
  860. end;  { TSpellDlg.AddWord }
  861.  
  862. function TSpellDlg.InDictionary (AWord: String): Boolean;
  863.   {-checks to see if the word is in the dictionary (no dialog)}
  864. begin
  865.   Result := DCT.InDictionary (AWord);
  866. end;  { TSpellDlg.InDictionary }
  867.  
  868. function TSpellDlg.SuggestWords (AWord: String; NumToList: Byte): TStringList;
  869.   {-suggests words}
  870. begin
  871.   Result := DCT.SuggestWords (AWord, NumToList);
  872. end;  { TSpellDlg.SuggestWords }
  873.  
  874. procedure Register;
  875. begin
  876.   RegisterComponents('Domain', [TSpellDlg]);
  877. end;  { Register }
  878.  
  879. end.  { EDSSpell }
  880.